import { XmPullRefresh } from "@/components/tool";
import { View } from "@tarojs/components";
import { RichText } from "@tarojs/components";
import { observer } from "mobx-react";
import React, { Fragment, useEffect, useState } from "react";
import { formatRichText } from "@/path/tool/until";
import { getRichTextData } from "@/path/api/setting/index"
import { Router, BaseRouter } from "@/path/router";
import Button from "@taroify/core/button/button";
import { userStore } from "@/store";
import "./index.scss"
function Index() {
  const [text, setText] = useState('')
  useEffect(() => {
    getRichTextData({ type: 4 }).then((res) => {
      setText(res.data.value)
    })
  }, [])

  // 打开签名页面
  const onSignature = () => {
    Router.toRegAgreementSign().then((res) => {
      if (res != null) BaseRouter.back({ data: res })
    })
  }
  /*
  * 更新资料操作
  */

  useEffect(() => {
  }, [userStore.userInfo])
  return <>
    <XmPullRefresh className="agreement" navigationStyle="custom">
      <RichText style="white-space: pre-wrap" nodes={formatRichText(text || "")}></RichText>
      <View className="agreement-btn">
        <Button color="primary" onClick={onSignature} shape="round" block>{userStore.userInfo.agreement ? "重新签字" : "阅读并签署协议"}</Button>
      </View>
    </XmPullRefresh>
  </>
}

const Higher = React.memo(observer(Index));
export default () => <Fragment><Higher /></Fragment>
